#!/usr/bin/evn python
# coding:utf-8
import os
import numpy as np

try:
    import xml.etree.cElementTree as ET
except ImportError:
    import xml.etree.ElementTree as ET
import sys

how_many_root_solved=0
how_many_frame_has_object = 0
total_frame = 0
path = "/home/sean/data/ILSVRC/Annotations/VID/val/"
list_dirs = os.walk(path, topdown=True)
for root, dirs, files in list_dirs:
    for f in files:
        file_path= os.path.join(root, f)
        tree = ET.parse(file_path)
        root_node = tree.getroot()
        object = root_node.find('object')
        total_frame += 1
        if object:
            how_many_frame_has_object += 1
        print(file_path)
    # how_many_root_solved += 1
    # if total_frame == 0:
        # continue
    # if float(how_many_frame_has_object/total_frame) <= 0.25:
        # print(root, how_many_frame_has_object, total_frame)
print(total_frame, total_frame - how_many_frame_has_object)

# for root, dirs, files in os.walk(path, topdown=False):
#     print(files)
# for file in files:
#     # print(os.path.join(root, file))
#     f = os.path.join(root, file)
#     name = file.split('.')
#     filename = name[0]
#     tree = ET.parse(f)  # 打开xml文档
#     root_node = tree.getroot()  # 获得root节点
#     root_node.find('filename').text=filename
#     print(filename)
#     write_path = path + file
#     tree.write(write_path)
